package se.energimyndigheten.lampguiden;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebView;

public class WebDialogFragment extends DialogFragment {

    private static final String TAG = WebDialogFragment.class.getSimpleName();
    private static final String PATH_FOLDER = MainActivity.HTML_BASEPATH + "Basta_ljuset/sv_";
    private static final String HTML_EXTENSION = ".html";

    private String mFile;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.web_dialog, container);
        WebView webView = (WebView) view.findViewById(R.id.webview);
        webView.loadUrl(PATH_FOLDER + mFile + HTML_EXTENSION);
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Dialog);
        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        return dialog;
    }

    public void show(FragmentManager fm, String tag, String file) {
        mFile = file;
        super.show(fm, tag);
    }
}
